﻿<%@ WebHandler Language="C#" Class="list" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.Script.Serialization;
using System.Web.SessionState;
using System.Web.Services;

public class list : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
    private StringBuilder sb = null;
    public DataSet ds = null;
    public DataTable dt = null;
    private string sqlwhere = "";
    public void ProcessRequest (HttpContext context) {
        string type = PageBase.ext_string(context.Request.Params["type"]);

        switch (type)
        {
            //获取订单列表
            case "getlist":
                getinfo_list(context);
                break;

            //传递简历
            case "post":
                post(context);
                break;

            default:
                //getinfo(context);
                break;
        }
    }

    //传递
    public void post(HttpContext context)
    {
        string getids = PageBase.ext_string(context.Request.Params["getids"]);
        string msg = "";
        bool flag;
        string sqlpost = "exec [ZDYSP_加载数据到同步表_逐个_OA] {0}";
        sqlpost = string.Format(sqlpost, getids);
        int dtcount= DBHelper5.ExecuteNonQuery(sqlpost);
        if (dtcount > 0)
        {
            flag = true;
            msg = "传递成功";

            string up_sql = "update LIK_TO202.satchioa.dbo.formtable_main_409 set ispostrs='Y' where id={0}";
            up_sql = string.Format(up_sql, getids);
            DBHelper.ExecuteNonQuery(up_sql);
        }
        else
        {
            flag = false;
            msg = "传递失败";

        }
        context.Response.Write("{\"flag\":\"" + flag + "\",\"remsg\":\"" + msg + "\"}");
        context.Response.ContentType = "text/json";
        context.Response.End();
    }

    //获取简历列表
    public void getinfo_list(HttpContext context)
    {
        //页数1
        int page = PageBase.ext_int(context.Request.Params["page"]);
        //每页条数10
        int limit =PageBase.ext_int(context.Request.Params["limit"]);
        //排序字段
        string field =PageBase.ext_string(context.Request.Params["field"]);
        //排序方式
        string order = PageBase.ext_string(context.Request.Params["order"]);


        string orderby = "sqrq desc";
        string where = @"select  COUNT(*) OVER(PARTITION BY 1) AS TOTAL,id,sqrq,lcbh,yzgw,name,
        birthday,zhuanye,shenfenzheng,yidongdianhua,ispostrs from LIK_TO202.satchioa.dbo.formtable_main_409 where 1=1 ";

        string jlname =PageBase.ext_string(context.Request.Params["jlname"]);
        string ksrq =PageBase.ext_string(context.Request.Params["ksrq"]);
        string jsrq =PageBase.ext_string(context.Request.Params["jsrq"]);
        //姓名
        if (!string.IsNullOrEmpty(jlname))
        {
            where += " and name like N'%" + jlname + "%'";
        }
        //店铺名称
        if (!string.IsNullOrEmpty(ksrq))
        {
            where += " and sqrq >='" + ksrq + "'";
        }
        //顾客名称
        if (!string.IsNullOrEmpty(jsrq))
        {
            where += " and sqrq<= '" + jsrq + "'";
        }

        if (!string.IsNullOrEmpty(order) && !string.IsNullOrEmpty(field))
        {
            orderby =field + " " + order;
        }
        DataTable dt =  DBHelper.Pagination2(where, limit, page, orderby, "");
        sb = new StringBuilder();
        string code = "0";
        string msg = "";
        int count = 0;
        if(dt.Rows.Count>0)
            count = PageBase.ext_int(dt.Rows[0]["TOTAL"].ToString());

        sb.Append("{\"code\":\"" + code + "\",\"count\":" + count + ",\"msg\":\"" + msg + "\",\"data\":[");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            sb.Append("{\"id\":\"" + dt.Rows[i]["id"].ToString() + "\"");
            sb.Append(",\"sqrq\":\"" + dt.Rows[i]["sqrq"] + "\"");
            sb.Append(",\"lcbh\":\"" + dt.Rows[i]["lcbh"] + "\"");
            sb.Append(",\"yzgw\":\"" + dt.Rows[i]["yzgw"] + "\"");
            sb.Append(",\"name\":\"" + dt.Rows[i]["name"] + "\"");
                 sb.Append(",\"ispostrs\":\"" + dt.Rows[i]["ispostrs"] + "\"");
            sb.Append(",\"birthday\":\"" + dt.Rows[i]["birthday"] + "\"");
            sb.Append(",\"zhuanye\":\"" + dt.Rows[i]["zhuanye"] + "\"");
            sb.Append(",\"shenfenzheng\":\"" + dt.Rows[i]["shenfenzheng"] + "\"");
            sb.Append(",\"yidongdianhua\":\"" + dt.Rows[i]["yidongdianhua"] + "\"}");
            if (i < dt.Rows.Count - 1)
            {
                sb.Append(",");
            }
        }
        sb.Append("]}");
        context.Response.Write(sb.ToString());
        context.Response.ContentType = "text/json";
        context.Response.End();
    }


    public bool IsReusable {
        get {
            return false;
        }
    }

}